package com.zjm.servlet.servlet06_http;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author ZJM
 * @date 2024/4/14 21:46
 * HttpServletResponse类
 * 响应
 */
@WebServlet("/resp")
public class ResponseServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 不能同时调用两种响应流
        // resp.getOutputStream();
        // resp.getWriter();
        // 处理中文乱码
        // resp.setCharacterEncoding("UTF-8");
        // resp.setHeader("Content-Type","text/html;charset=UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        System.out.println(resp.getCharacterEncoding());

        PrintWriter writer = resp.getWriter();
        writer.write("res");
        writer.append("主站");
    }
}
